public class QueueStack {

        private Queue<Integer> qu1;
        private Queue<Integer> qu2;

        public MyStack() {
            qu1=new LinkedList<>();
            qu2=new LinkedList<>();
        }

        public void push(int x) {
            if(!qu1.isEmpty()) {
                qu1.offer(x);
            }else if(!qu2.isEmpty()) {
                qu2.offer(x);
            }else{
                qu1.offer(x);
            }
        }

        public int pop() {
            if(empty()) {
                return -1;
            }
            int size1=qu1.size();
            int size2=qu2.size();
            if(!qu1.isEmpty()){
                for(int i=0;i<size1;i++) {
                    int x=qu1.poll();
                    qu2.offer(x);
                }
                return qu2.poll();
            }else{
                for(int i=0;i<size2;i++) {
                    int x=qu2.poll();
                    qu1.offer(x);
                }
                return qu1.poll();
            }
        }

        public int top() {
            if(empty()) {
                return -1;
            }
            int size1=qu1.size();
            int size2=qu2.size();
            if(!qu1.isEmpty()){

                for(int i=0;i<size1;i++) {
                    int x=qu1.poll();
                    qu2.offer(x);
                }
                return qu2.peek();
            }else{
                for(int i=0;i<size2;i++) {
                    int x=qu2.poll();
                    qu1.offer(x);
                }
                return qu1.peek();
            }

        }

        public boolean empty() {
            if(qu1.isEmpty()&&qu2.isEmpty()) {
                return true;
            }
            return false;

        }
    }

